﻿using System;
using System.Runtime.Serialization;

namespace FBGraph
{
    /// <summary>A wrapper for Graph API responses that only return an ID.</summary>
    /// <seealso cref="ListResult{TItem}" />
    /// <seealso cref="PagedResult{TItem}" />
    /// <seealso cref="DictionaryResult{TItem}" />
    [DataContract(Name = "idResult")]
    public class IdResult : IFBGraphResult
    {
        /// <summary>Gets or sets the id that was returned by the Graph API.</summary>
        [DataMember(Name = "id")]
        public String Id { get; set; }

        #region [ IFBGraphResult Members ]

        /// <summary>Gets or sets a <see cref="Boolean" /> value representing whether the object has been populated.</summary>
        protected virtual Boolean IsReady { get; set; }
        Boolean IFBGraphResult.IsReady
        {
            get { return this.IsReady; }
            set { this.IsReady = value; }
        }

        void IFBGraphResult.UpdateFrom(IFBGraphResult other)
        {            
            if (other is IFBGraphResult)
            {
                this.Id = ((IdResult)other).Id;
            }
        }

        #endregion

        /// <summary>Returns the <see cref="String" /> representation of the current <see cref="IdResult" />.</summary>
        /// <returns>The <see cref="String" /> representation of the current <see cref="IdResult" />.</returns>
        public override String ToString()
        {
            return this.Id;
        }

        /// <summary>Returns the <see cref="String" /> representation of the current <see cref="IdResult" />.</summary>
        /// <param name="result">The <see cref="IdResult" />.</param>
        /// <returns>The <see cref="String" /> representation of the current <see cref="IdResult" />.</returns>
        public static implicit operator String(IdResult result)
        {
            return result.Id;
        }
    }
}